/* colorbar.h */

#ifndef DODO_COLORBAR_H
#define DODO_COLORBAR_H

#include <dodo_plot/kernel/plotfwd.h>
#include <dodo_plot/kernel/basic_elements.h>
#include <dodo_plot/kernel/colormap.h>
#include <dodo_plot/widget/axis.h>

namespace dodo_plot
{
/**
 * 色标. 
 */
/// 色标
class Colorbar
{
public:
	/// 水平或垂直
	enum { HORIZONTAL, VERTICAL };
public:
	/**
	 * \param colormap 所用的Colormap. 
	 * \param axis 所用的Axis. axis本身的线条和刻度将会按Colorbar自身的样式来绘制, 即axis的色彩, 粗细, 标签等信息将传递给Colorbar.
	 * \param mode 模式, 可选为Axis::HORIZONTAL, Axis::VERTICAL. 
	 * \param draw_arrow 是否绘制两端的箭头. 
	 */
	Colorbar(double width, double height, const Colormap& colormap, const Axis& axis, int mode, bool draw_arrow = false);

	/**
	 * 由一对迭代器来确定所用的色彩, 而非由一个Colormap. 
	 * TODO: 此时尚无法单独指定两端极限的色彩. 
	 * \param axis 所用的Axis. axis本身的线条和刻度将会按Colorbar自身的样式来绘制, 即axis的色彩, 粗细, 标签等信息将传递给Colorbar.
	 * \param mode 模式, 可选为Axis::HORIZONTAL, Axis::VERTICAL. 
	 * \param draw_arrow 是否绘制两端的箭头. 
	 */
	template<class Iter>
	Colorbar(double width, double height, Iter b, Iter e, const Axis& axis, int mode, bool draw_arrow = false);
public:
	void set_border_color(const Color& color);
	void set_border_width(double width);
	/// tick_length_ratio为Colorbar中刻度线占宽度的比例. 值为0是完全没有刻度线, 值为1时占满宽度. 
	void set_tick_length_ratio(double ratio);
	void set_label_distance(double distance);
	void set_label_align_mode(int mode);

public:
	double width() const {return w_;}
	double height() const {return h_;}
	Position local_pos() const {return Position(0, 1, 0, 1);}
	void draw(const Plotter& plotter) const;
private:
	void apply_default();

protected:
	Colormap colormap_;	
	Axis axis_;
	int mode_;
	bool draw_arrow_;
	double w_, h_;
	Color border_color_;
	double border_width_;
	double tick_length_ratio_;
};

//Impletment
template<class Iter>
Colorbar::Colorbar(double width, double height, Iter b, Iter e, const Axis& axis, int mode, bool draw_arrow)
	: w_(width), h_(height),
	colormap_(b, e), axis_(axis),
	mode_(mode),
	draw_arrow_(draw_arrow)
{
	apply_default();
}

}

#endif //DODO_COLORBAR_H

